from django.urls import path, include
from rest_framework.routers import DefaultRouter
from . import views
from .viewsets import PermissionViewSet, RoleViewSet, UserViewSet, MenuViewSet

# 创建路由器
router = DefaultRouter()
router.register(r'permissions', PermissionViewSet)
router.register(r'roles', RoleViewSet)
router.register(r'users', UserViewSet)
router.register(r'menus', MenuViewSet)

urlpatterns = [
    # ViewSet路由
    path('', include(router.urls)),

    # 兼容旧版API（如果需要）
    path('legacy/permissions/', views.permission_list, name='permission_list'),
    path('legacy/permissions/<int:pk>/', views.permission_detail, name='permission_detail'),
    path('legacy/roles/', views.role_list, name='role_list'),
    path('legacy/roles/<int:pk>/', views.role_detail, name='role_detail'),
    path('legacy/users/', views.user_list, name='user_list'),
    path('legacy/users/<int:pk>/', views.user_detail, name='user_detail'),
    path('legacy/menus/', views.menu_list, name='menu_list'),
    path('legacy/menus/<int:pk>/', views.menu_detail, name='menu_detail'),
    path('legacy/user-menus/', views.user_menus, name='user_menus'),
]
